import androidx.compose.desktop.Window
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import remote.Remote
import remote.domain.Ok
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

fun main() = Window {
    var text by remember { mutableStateOf("Hello, World!") }

    MaterialTheme {
        val typography = MaterialTheme.typography
        Column(
            modifier = Modifier.padding(16.dp)
        ) {
            Button(onClick = {
                text = "loading..."
                Remote.service.ok().enqueue(object : Callback<Ok> {

                    override fun onResponse(call: Call<Ok>, response: Response<Ok>) {
                        response.body()?.let { it ->
                            text = it.msg
                        }
                    }

                    override fun onFailure(call: Call<Ok>, t: Throwable) {
                        t.printStackTrace()
                    }
                })
            }) {
                Text(text)
            }

            Text(
                "A day wandering through the sandhills " +
                        "in Shark Fin Cove, and a few of the " +
                        "sights I saw",
                style = typography.h6,
                maxLines = 2,
                overflow = TextOverflow.Ellipsis
            )
            Text(
                "Davenport, California",
                style = typography.body2
            )
            Text(
                "December 2018",
                style = typography.body2
            )
        }

    }
}